package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.DiscussBean;
import com.project.bean.TopicBean;
import com.project.mapper.IDiscussMapper;
import com.project.mapper.ITopicMapper;
import com.project.service.ITopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDate;

@Service
public class TopicServiceImpl implements ITopicService {
    @Autowired
    private ITopicMapper mapper;
    @Autowired
    private IDiscussMapper discussMapper;

    @Override
    public PageInfo<TopicBean> cutByItem(int pageNO, int channelId , String topicName, String authName, LocalDate startDate,LocalDate endDate) {
        PageHelper.startPage(pageNO,3);
        PageInfo info=PageInfo.of(mapper.cutByItem(channelId,topicName,authName,startDate,endDate));
        return info;
    }

    @Override
    public void add(TopicBean topicBean) {
        mapper.add(topicBean);
    }

    @Override
    public TopicBean findById(int id) {
        TopicBean topicBean=mapper.findById(id);
        topicBean.setList(discussMapper.findByTopic(id));
        return topicBean;
    }
}
